package com.fgs.common.uploadPicture.compress.luban;

import android.graphics.Bitmap;

import com.fgs.common.uploadPicture.compress.IPictureCompress;
import com.fgs.common.uploadPicture.compress.OnPictureCompressListener;
import com.fgs.common.utils.CommonUtil;
import com.fgs.common.utils.ImageUtil;
import com.fgs.common.widget.CustomProgressDialog;

import java.io.File;

import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

/**
 * @author fgs
 * @date 2020/10/17
 * @description
 **/
public class LuBanPictureCompress implements IPictureCompress {


    public LuBanPictureCompress() {
    }

    @Override
    public void pictureCompress(File file, OnPictureCompressListener compressListener) {
        if (file == null) return;
        Luban.with(CommonUtil.getContext()).load(file).setCompressListener(new OnCompressListener() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(File file) {

                if (compressListener != null)
                    compressListener.onSuccess(file);
            }

            @Override
            public void onError(Throwable e) {
                if (compressListener != null)
                    compressListener.onError(e);
            }
        }).launch();
    }

    @Override
    public void pictureCompress(Bitmap bitmap, OnPictureCompressListener compressListener) {

        pictureCompress(ImageUtil.getFile(bitmap), compressListener);
    }

}
